import java.util.Map;
import java.util.TreeMap;

public class Solution1146 {

    TreeMap<Integer,Integer>[] maps;
    int context=0;

    public Solution1146(int length) {
        maps=new TreeMap[length];
        for (int i=0;i<maps.length;i++){
            maps[i]= new TreeMap<>();
        }
    }

    public void set(int index, int val) {
        maps[index].put(context,val);
    }

    public int snap() {
        context++;
        return context-1;
    }

    public int get(int index, int snap_id) {
        Map.Entry<Integer, Integer> entry = maps[index].floorEntry(snap_id);
        if (entry==null){
            return 0;
        }else {
            return entry.getValue();
        }
    }

    public static void main(String[] args) {
        Solution1146 solution1146=new Solution1146(3);
        solution1146.set(0,15);
        System.out.println(solution1146.snap());
        System.out.println(solution1146.snap());
        System.out.println(solution1146.snap());
        solution1146.set(0,6);
        System.out.println(solution1146.get(0, 2));
    }
}
